package com.jlf.core.annotation.restful.method;

import io.swagger.v3.oas.annotations.Operation;
import org.springframework.core.annotation.AliasFor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.lang.annotation.*;

/**
 * 接口资源的注解定义
 *
 * @author wujr
 * 2020/11/13
 * @version 1.0
 * 变更历史
 * [wujr 2020/11/13 1.0 新增]
 */
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RequestMapping
@Operation
public @interface RestfulApi {

    /**
     * 接口是否允许匿名访问
     * true——允许
     * false——禁止
     * @return 是否允许匿名
     */
    boolean anonymous() default false;
    /**
     * 接口是否需要授权访问
     * true——需要
     * false——不需要
     * @return 是否需要授权
     */
    boolean authorize() default true;
    /**
     * 接口的编码
     * Alias for {@link RequestMapping#name}.
     * @return 编码
     */
    @AliasFor(annotation = RequestMapping.class, value = "name")
    String code() default "";

    @AliasFor(annotation = Operation.class, value = "operationId")
    String id() default "";
    /**
     * 接口的名称
     * @return 名称
     */
    @AliasFor(annotation = Operation.class, value = "summary")
    String name() default "";

    @AliasFor(annotation = Operation.class, value = "tags")
    String[] tags() default {};

    /**
     * 是否进行合并
     * name+ApiController.domainName
     * code+ApiController.domainCode
     * @return true表示需要合并称为一个完整的名称和编码
     */
    boolean merge() default true;

    /**
     * 是否忽略扫描
     * @return true表示该接口需要被忽略扫描
     */
    boolean ignoreScan() default false;

    /**
     * 接口的备注
     * @return 备注
     */
    @AliasFor(annotation = Operation.class, value = "description")
    String remark() default "";

    /**
     * Alias for {@link RequestMapping#value}.
     * @return 请求值
     */
    @AliasFor(annotation = RequestMapping.class)
    String[] value() default {};

    /**
     * Alias for {@link RequestMapping#path}.
     * @return 接口地址
     */
    @AliasFor(annotation = RequestMapping.class)
    String[] path() default {};

    /**
     * Alias for {@link RequestMapping#params}.
     * @return 请求参数
     */
    @AliasFor(annotation = RequestMapping.class)
    String[] params() default {};

    /**
     * Alias for {@link RequestMapping#headers}.
     * @return 头部参数
     */
    @AliasFor(annotation = RequestMapping.class)
    String[] headers() default {};

    /**
     * Alias for {@link RequestMapping#consumes}.
     * @return 消费者信息
     */
    @AliasFor(annotation = RequestMapping.class)
    String[] consumes() default {};

    /**
     * Alias for {@link RequestMapping#produces}.
     * 如果controller的某个接口直接返回的是string，同时还是希望进行统一输出封装，则需要添加
     * produces = MediaType.APPLICATION_JSON_VALUE
     * @return 生产者信息
     */
    @AliasFor(annotation = RequestMapping.class)
    String[] produces() default {};

    /**
     * The HTTP request methods to map to, narrowing the primary mapping:
     * GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE, TRACE.
     * <p><b>Supported at the type level as well as at the method level!</b>
     * When used at the type level, all method-level mappings inherit
     * this HTTP method restriction (i.e. the type-level restriction
     * gets checked before the handler method is even resolved).
     * @return 请求方式
     */
    @AliasFor(annotation = RequestMapping.class)
    RequestMethod[] method() default {};

    /**
     * 该接口适用的角色列表
     * 当application的authorizeMode=
     * @return 角色列表，参考ActorProfile.roleType
     */
    int[] roleType() default {};
}
